<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>treenode.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_structs_treenode.js.html">treenode.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Generic tree node data structure with arbitrary number of child
<a name="line17"></a> * nodes.
<a name="line18"></a> *
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.structs.TreeNode&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line25"></a>goog.require(&#39;goog.structs.Node&#39;);
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>
<a name="line29"></a>/**
<a name="line30"></a> * Generic tree node data structure with arbitrary number of child nodes.
<a name="line31"></a> * It is possible to create a dynamic tree structure by overriding
<a name="line32"></a> * {@link #getParent} and {@link #getChildren} in a subclass. All other getters
<a name="line33"></a> * will automatically work.
<a name="line34"></a> *
<a name="line35"></a> * @param {KEY} key Key.
<a name="line36"></a> * @param {VALUE} value Value.
<a name="line37"></a> * @constructor
<a name="line38"></a> * @extends {goog.structs.Node.&lt;KEY, VALUE&gt;}
<a name="line39"></a> * @template KEY, VALUE
<a name="line40"></a> */
<a name="line41"></a>goog.structs.TreeNode = function(key, value) {
<a name="line42"></a>  goog.structs.Node.call(this, key, value);
<a name="line43"></a>
<a name="line44"></a>  /**
<a name="line45"></a>   * Reference to the parent node or null if it has no parent.
<a name="line46"></a>   * @private {goog.structs.TreeNode.&lt;KEY, VALUE&gt;}
<a name="line47"></a>   */
<a name="line48"></a>  this.parent_ = null;
<a name="line49"></a>
<a name="line50"></a>  /**
<a name="line51"></a>   * Child nodes or null in case of leaf node.
<a name="line52"></a>   * @private {Array.&lt;!goog.structs.TreeNode.&lt;KEY, VALUE&gt;&gt;}
<a name="line53"></a>   */
<a name="line54"></a>  this.children_ = null;
<a name="line55"></a>};
<a name="line56"></a>goog.inherits(goog.structs.TreeNode, goog.structs.Node);
<a name="line57"></a>
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * Constant for empty array to avoid unnecessary allocations.
<a name="line61"></a> * @private
<a name="line62"></a> */
<a name="line63"></a>goog.structs.TreeNode.EMPTY_ARRAY_ = [];
<a name="line64"></a>
<a name="line65"></a>
<a name="line66"></a>/**
<a name="line67"></a> * @return {!goog.structs.TreeNode} Clone of the tree node without its parent
<a name="line68"></a> *     and child nodes. The key and the value are copied by reference.
<a name="line69"></a> * @override
<a name="line70"></a> */
<a name="line71"></a>goog.structs.TreeNode.prototype.clone = function() {
<a name="line72"></a>  return new goog.structs.TreeNode(this.getKey(), this.getValue());
<a name="line73"></a>};
<a name="line74"></a>
<a name="line75"></a>
<a name="line76"></a>/**
<a name="line77"></a> * @return {!goog.structs.TreeNode} Clone of the subtree with this node as root.
<a name="line78"></a> */
<a name="line79"></a>goog.structs.TreeNode.prototype.deepClone = function() {
<a name="line80"></a>  var clone = this.clone();
<a name="line81"></a>  this.forEachChild(function(child) {
<a name="line82"></a>    clone.addChild(child.deepClone());
<a name="line83"></a>  });
<a name="line84"></a>  return clone;
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} Parent node or null if it has no
<a name="line90"></a> *     parent.
<a name="line91"></a> */
<a name="line92"></a>goog.structs.TreeNode.prototype.getParent = function() {
<a name="line93"></a>  return this.parent_;
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * @return {boolean} Whether the node is a leaf node.
<a name="line99"></a> */
<a name="line100"></a>goog.structs.TreeNode.prototype.isLeaf = function() {
<a name="line101"></a>  return !this.getChildCount();
<a name="line102"></a>};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * Tells if the node is the last child of its parent. This method helps how to
<a name="line107"></a> * connect the tree nodes with lines: L shapes should be used before the last
<a name="line108"></a> * children and |- shapes before the rest. Schematic tree visualization:
<a name="line109"></a> *
<a name="line110"></a> * &lt;pre&gt;
<a name="line111"></a> * Node1
<a name="line112"></a> * |-Node2
<a name="line113"></a> * | L-Node3
<a name="line114"></a> * |   |-Node4
<a name="line115"></a> * |   L-Node5
<a name="line116"></a> * L-Node6
<a name="line117"></a> * &lt;/pre&gt;
<a name="line118"></a> *
<a name="line119"></a> * @return {boolean} Whether the node has parent and is the last child of it.
<a name="line120"></a> */
<a name="line121"></a>goog.structs.TreeNode.prototype.isLastChild = function() {
<a name="line122"></a>  var parent = this.getParent();
<a name="line123"></a>  return Boolean(parent &amp;&amp; this == goog.array.peek(parent.getChildren()));
<a name="line124"></a>};
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * @return {!Array.&lt;!goog.structs.TreeNode.&lt;KEY, VALUE&gt;&gt;} Immutable child nodes.
<a name="line129"></a> */
<a name="line130"></a>goog.structs.TreeNode.prototype.getChildren = function() {
<a name="line131"></a>  return this.children_ || goog.structs.TreeNode.EMPTY_ARRAY_;
<a name="line132"></a>};
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Gets the child node of this node at the given index.
<a name="line137"></a> * @param {number} index Child index.
<a name="line138"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The node at the given index or
<a name="line139"></a> *     null if not found.
<a name="line140"></a> */
<a name="line141"></a>goog.structs.TreeNode.prototype.getChildAt = function(index) {
<a name="line142"></a>  return this.getChildren()[index] || null;
<a name="line143"></a>};
<a name="line144"></a>
<a name="line145"></a>
<a name="line146"></a>/**
<a name="line147"></a> * @return {number} The number of children.
<a name="line148"></a> */
<a name="line149"></a>goog.structs.TreeNode.prototype.getChildCount = function() {
<a name="line150"></a>  return this.getChildren().length;
<a name="line151"></a>};
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * @return {number} The number of ancestors of the node.
<a name="line156"></a> */
<a name="line157"></a>goog.structs.TreeNode.prototype.getDepth = function() {
<a name="line158"></a>  var depth = 0;
<a name="line159"></a>  var node = this;
<a name="line160"></a>  while (node.getParent()) {
<a name="line161"></a>    depth++;
<a name="line162"></a>    node = node.getParent();
<a name="line163"></a>  }
<a name="line164"></a>  return depth;
<a name="line165"></a>};
<a name="line166"></a>
<a name="line167"></a>
<a name="line168"></a>/**
<a name="line169"></a> * @return {!Array.&lt;!goog.structs.TreeNode.&lt;KEY, VALUE&gt;&gt;} All ancestor nodes in
<a name="line170"></a> *     bottom-up order.
<a name="line171"></a> */
<a name="line172"></a>goog.structs.TreeNode.prototype.getAncestors = function() {
<a name="line173"></a>  var ancestors = [];
<a name="line174"></a>  var node = this.getParent();
<a name="line175"></a>  while (node) {
<a name="line176"></a>    ancestors.push(node);
<a name="line177"></a>    node = node.getParent();
<a name="line178"></a>  }
<a name="line179"></a>  return ancestors;
<a name="line180"></a>};
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * @return {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The root of the tree structure,
<a name="line185"></a> *     i.e. the farthest ancestor of the node or the node itself if it has no
<a name="line186"></a> *     parents.
<a name="line187"></a> */
<a name="line188"></a>goog.structs.TreeNode.prototype.getRoot = function() {
<a name="line189"></a>  var root = this;
<a name="line190"></a>  while (root.getParent()) {
<a name="line191"></a>    root = root.getParent();
<a name="line192"></a>  }
<a name="line193"></a>  return root;
<a name="line194"></a>};
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * Builds a nested array structure from the node keys in this node&#39;s subtree to
<a name="line199"></a> * facilitate testing tree operations that change the hierarchy.
<a name="line200"></a> * @return {!Array.&lt;KEY&gt;} The structure of this node&#39;s descendants as nested
<a name="line201"></a> *     array of node keys. The number of unclosed opening brackets up to a
<a name="line202"></a> *     particular node is proportional to the indentation of that node in the
<a name="line203"></a> *     graphical representation of the tree. Example:
<a name="line204"></a> *     &lt;pre&gt;
<a name="line205"></a> *       this
<a name="line206"></a> *       |- child1
<a name="line207"></a> *       |  L- grandchild
<a name="line208"></a> *       L- child2
<a name="line209"></a> *     &lt;/pre&gt;
<a name="line210"></a> *     is represented as [&#39;child1&#39;, [&#39;grandchild&#39;], &#39;child2&#39;].
<a name="line211"></a> */
<a name="line212"></a>goog.structs.TreeNode.prototype.getSubtreeKeys = function() {
<a name="line213"></a>  var ret = [];
<a name="line214"></a>  this.forEachChild(function(child) {
<a name="line215"></a>    ret.push(child.getKey());
<a name="line216"></a>    if (!child.isLeaf()) {
<a name="line217"></a>      ret.push(child.getSubtreeKeys());
<a name="line218"></a>    }
<a name="line219"></a>  });
<a name="line220"></a>  return ret;
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/**
<a name="line225"></a> * Tells whether this node is the ancestor of the given node.
<a name="line226"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} node A node.
<a name="line227"></a> * @return {boolean} Whether this node is the ancestor of {@code node}.
<a name="line228"></a> */
<a name="line229"></a>goog.structs.TreeNode.prototype.contains = function(node) {
<a name="line230"></a>  var current = node;
<a name="line231"></a>  do {
<a name="line232"></a>    current = current.getParent();
<a name="line233"></a>  } while (current &amp;&amp; current != this);
<a name="line234"></a>  return Boolean(current);
<a name="line235"></a>};
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/**
<a name="line239"></a> * Finds the deepest common ancestor of the given nodes. The concept of
<a name="line240"></a> * ancestor is not strict in this case, it includes the node itself.
<a name="line241"></a> * @param {...!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} var_args The nodes.
<a name="line242"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The common ancestor of the nodes
<a name="line243"></a> *     or null if they are from different trees.
<a name="line244"></a> * @template KEY, VALUE
<a name="line245"></a> */
<a name="line246"></a>goog.structs.TreeNode.findCommonAncestor = function(var_args) {
<a name="line247"></a>  var ret = arguments[0];
<a name="line248"></a>  if (!ret) {
<a name="line249"></a>    return null;
<a name="line250"></a>  }
<a name="line251"></a>
<a name="line252"></a>  var retDepth = ret.getDepth();
<a name="line253"></a>  for (var i = 1; i &lt; arguments.length; i++) {
<a name="line254"></a>    var node = arguments[i];
<a name="line255"></a>    var depth = node.getDepth();
<a name="line256"></a>    while (node != ret) {
<a name="line257"></a>      if (depth &lt;= retDepth) {
<a name="line258"></a>        ret = ret.getParent();
<a name="line259"></a>        retDepth--;
<a name="line260"></a>      }
<a name="line261"></a>      if (depth &gt; retDepth) {
<a name="line262"></a>        node = node.getParent();
<a name="line263"></a>        depth--;
<a name="line264"></a>      }
<a name="line265"></a>    }
<a name="line266"></a>  }
<a name="line267"></a>
<a name="line268"></a>  return ret;
<a name="line269"></a>};
<a name="line270"></a>
<a name="line271"></a>
<a name="line272"></a>/**
<a name="line273"></a> * Returns a node whose key matches the given one in the hierarchy rooted at
<a name="line274"></a> * this node. The hierarchy is searched using an in-order traversal.
<a name="line275"></a> * @param {KEY} key The key to search for.
<a name="line276"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The node with the given key, or
<a name="line277"></a> *     null if no node with the given key exists in the hierarchy.
<a name="line278"></a> */
<a name="line279"></a>goog.structs.TreeNode.prototype.getNodeByKey = function(key) {
<a name="line280"></a>  if (this.getKey() == key) {
<a name="line281"></a>    return this;
<a name="line282"></a>  }
<a name="line283"></a>  var children = this.getChildren();
<a name="line284"></a>  for (var i = 0; i &lt; children.length; i++) {
<a name="line285"></a>    var descendant = children[i].getNodeByKey(key);
<a name="line286"></a>    if (descendant) {
<a name="line287"></a>      return descendant;
<a name="line288"></a>    }
<a name="line289"></a>  }
<a name="line290"></a>  return null;
<a name="line291"></a>};
<a name="line292"></a>
<a name="line293"></a>
<a name="line294"></a>/**
<a name="line295"></a> * Traverses all child nodes.
<a name="line296"></a> * @param {function(this:THIS, !goog.structs.TreeNode.&lt;KEY, VALUE&gt;, number,
<a name="line297"></a> *     !Array.&lt;!goog.structs.TreeNode.&lt;KEY, VALUE&gt;&gt;)} f Callback function. It
<a name="line298"></a> *     takes the node, its index and the array of all child nodes as arguments.
<a name="line299"></a> * @param {THIS=} opt_this The object to be used as the value of {@code this}
<a name="line300"></a> *     within {@code f}.
<a name="line301"></a> * @template THIS
<a name="line302"></a> */
<a name="line303"></a>goog.structs.TreeNode.prototype.forEachChild = function(f, opt_this) {
<a name="line304"></a>  goog.array.forEach(this.getChildren(), f, opt_this);
<a name="line305"></a>};
<a name="line306"></a>
<a name="line307"></a>
<a name="line308"></a>/**
<a name="line309"></a> * Traverses all child nodes recursively in preorder.
<a name="line310"></a> * @param {function(!goog.structs.TreeNode.&lt;KEY, VALUE&gt;)} f Callback function.
<a name="line311"></a> *     It takes the node as argument.
<a name="line312"></a> * @param {Object=} opt_this The object to be used as the value of {@code this}
<a name="line313"></a> *     within {@code f}.
<a name="line314"></a> */
<a name="line315"></a>goog.structs.TreeNode.prototype.forEachDescendant = function(f, opt_this) {
<a name="line316"></a>  goog.array.forEach(this.getChildren(), function(child) {
<a name="line317"></a>    f.call(opt_this, child);
<a name="line318"></a>    child.forEachDescendant(f, opt_this);
<a name="line319"></a>  });
<a name="line320"></a>};
<a name="line321"></a>
<a name="line322"></a>
<a name="line323"></a>/**
<a name="line324"></a> * Traverses the subtree with the possibility to skip branches. Starts with
<a name="line325"></a> * this node, and visits the descendant nodes depth-first, in preorder.
<a name="line326"></a> * @param {function(this:THIS, !goog.structs.TreeNode.&lt;KEY, VALUE&gt;):
<a name="line327"></a> *     (boolean|undefined)} f Callback function. It takes the node as argument.
<a name="line328"></a> *     The children of this node will be visited if the callback returns true or
<a name="line329"></a> *     undefined, and will be skipped if the callback returns false.
<a name="line330"></a> * @param {THIS=} opt_this The object to be used as the value of {@code this}
<a name="line331"></a> *     within {@code f}.
<a name="line332"></a> * @template THIS
<a name="line333"></a> */
<a name="line334"></a>goog.structs.TreeNode.prototype.traverse = function(f, opt_this) {
<a name="line335"></a>  if (f.call(opt_this, this) !== false) {
<a name="line336"></a>    goog.array.forEach(this.getChildren(), function(child) {
<a name="line337"></a>      child.traverse(f, opt_this);
<a name="line338"></a>    });
<a name="line339"></a>  }
<a name="line340"></a>};
<a name="line341"></a>
<a name="line342"></a>
<a name="line343"></a>/**
<a name="line344"></a> * Sets the parent node of this node. The callers must ensure that the parent
<a name="line345"></a> * node and only that has this node among its children.
<a name="line346"></a> * @param {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} parent The parent to set. If
<a name="line347"></a> *     null, the node will be detached from the tree.
<a name="line348"></a> * @protected
<a name="line349"></a> */
<a name="line350"></a>goog.structs.TreeNode.prototype.setParent = function(parent) {
<a name="line351"></a>  this.parent_ = parent;
<a name="line352"></a>};
<a name="line353"></a>
<a name="line354"></a>
<a name="line355"></a>/**
<a name="line356"></a> * Appends a child node to this node.
<a name="line357"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} child Orphan child node.
<a name="line358"></a> */
<a name="line359"></a>goog.structs.TreeNode.prototype.addChild = function(child) {
<a name="line360"></a>  this.addChildAt(child, this.children_ ? this.children_.length : 0);
<a name="line361"></a>};
<a name="line362"></a>
<a name="line363"></a>
<a name="line364"></a>/**
<a name="line365"></a> * Inserts a child node at the given index.
<a name="line366"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} child Orphan child node.
<a name="line367"></a> * @param {number} index The position to insert at.
<a name="line368"></a> */
<a name="line369"></a>goog.structs.TreeNode.prototype.addChildAt = function(child, index) {
<a name="line370"></a>  goog.asserts.assert(!child.getParent());
<a name="line371"></a>  child.setParent(this);
<a name="line372"></a>  this.children_ = this.children_ || [];
<a name="line373"></a>  goog.asserts.assert(index &gt;= 0 &amp;&amp; index &lt;= this.children_.length);
<a name="line374"></a>  goog.array.insertAt(this.children_, child, index);
<a name="line375"></a>};
<a name="line376"></a>
<a name="line377"></a>
<a name="line378"></a>/**
<a name="line379"></a> * Replaces a child node at the given index.
<a name="line380"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} newChild Child node to set. It
<a name="line381"></a> *     must not have parent node.
<a name="line382"></a> * @param {number} index Valid index of the old child to replace.
<a name="line383"></a> * @return {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The original child node,
<a name="line384"></a> *     detached from its parent.
<a name="line385"></a> */
<a name="line386"></a>goog.structs.TreeNode.prototype.replaceChildAt = function(newChild, index) {
<a name="line387"></a>  goog.asserts.assert(!newChild.getParent(),
<a name="line388"></a>      &#39;newChild must not have parent node&#39;);
<a name="line389"></a>  var children = this.getChildren();
<a name="line390"></a>  var oldChild = children[index];
<a name="line391"></a>  goog.asserts.assert(oldChild, &#39;Invalid child or child index is given.&#39;);
<a name="line392"></a>  oldChild.setParent(null);
<a name="line393"></a>  children[index] = newChild;
<a name="line394"></a>  newChild.setParent(this);
<a name="line395"></a>  return oldChild;
<a name="line396"></a>};
<a name="line397"></a>
<a name="line398"></a>
<a name="line399"></a>/**
<a name="line400"></a> * Replaces the given child node.
<a name="line401"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} newChild New node to replace
<a name="line402"></a> *     {@code oldChild}. It must not have parent node.
<a name="line403"></a> * @param {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} oldChild Existing child node to
<a name="line404"></a> *     be replaced.
<a name="line405"></a> * @return {!goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The replaced child node
<a name="line406"></a> *     detached from its parent.
<a name="line407"></a> */
<a name="line408"></a>goog.structs.TreeNode.prototype.replaceChild = function(newChild, oldChild) {
<a name="line409"></a>  return this.replaceChildAt(newChild,
<a name="line410"></a>      goog.array.indexOf(this.getChildren(), oldChild));
<a name="line411"></a>};
<a name="line412"></a>
<a name="line413"></a>
<a name="line414"></a>/**
<a name="line415"></a> * Removes the child node at the given index.
<a name="line416"></a> * @param {number} index The position to remove from.
<a name="line417"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The removed node if any.
<a name="line418"></a> */
<a name="line419"></a>goog.structs.TreeNode.prototype.removeChildAt = function(index) {
<a name="line420"></a>  var child = this.children_ &amp;&amp; this.children_[index];
<a name="line421"></a>  if (child) {
<a name="line422"></a>    child.setParent(null);
<a name="line423"></a>    goog.array.removeAt(this.children_, index);
<a name="line424"></a>    if (this.children_.length == 0) {
<a name="line425"></a>      delete this.children_;
<a name="line426"></a>    }
<a name="line427"></a>    return child;
<a name="line428"></a>  }
<a name="line429"></a>  return null;
<a name="line430"></a>};
<a name="line431"></a>
<a name="line432"></a>
<a name="line433"></a>/**
<a name="line434"></a> * Removes the given child node of this node.
<a name="line435"></a> * @param {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} child The node to remove.
<a name="line436"></a> * @return {goog.structs.TreeNode.&lt;KEY, VALUE&gt;} The removed node if any.
<a name="line437"></a> */
<a name="line438"></a>goog.structs.TreeNode.prototype.removeChild = function(child) {
<a name="line439"></a>  return this.removeChildAt(goog.array.indexOf(this.getChildren(), child));
<a name="line440"></a>};
<a name="line441"></a>
<a name="line442"></a>
<a name="line443"></a>/**
<a name="line444"></a> * Removes all child nodes of this node.
<a name="line445"></a> */
<a name="line446"></a>goog.structs.TreeNode.prototype.removeChildren = function() {
<a name="line447"></a>  if (this.children_) {
<a name="line448"></a>    goog.array.forEach(this.children_, function(child) {
<a name="line449"></a>      child.setParent(null);
<a name="line450"></a>    });
<a name="line451"></a>  }
<a name="line452"></a>  delete this.children_;
<a name="line453"></a>};
</pre>


</body>
</html>
